const { find: findMovies, add: addMovie, patch: patchMovie, put: putMovie } = require('../model/movies')

const find = async (req, res, next) => {
  let result = await findMovies()

  res.render('movies', {
    data: JSON.stringify(result)
  })
}

const add = async (req, res, next) => {
  let body = req.body
  let result = await addMovie(body)
  if (result) {
    res.render('movies', {
      data: JSON.stringify({
        msg: '添加成功'
      })
    })
  }
}

const patch = async (req, res, next) => {
  let body = req.body
  let result = await patchMovie(body)
  if (result) {
    res.render('movies', {
      data: JSON.stringify({
        msg: '修改成功'
      })
    })
  }
}

const put = async (req, res, next) => {
  let body = req.body
  let result = await putMovie(body)
  console.log(result)
  if (result) {
    res.render('movies', {
      data: JSON.stringify({
        msg: '修改成功'
      })
    })
  }
}



module.exports = {
  find,
  add,
  patch,
  put
}